/*
 * @lc app=leetcode.cn id=1582 lang=typescript
 *
 * [1582] 二进制矩阵中的特殊位置
 */

// @lc code=start
function numSpecial(mat: number[][]): number {
    let count = 0;
    mat.forEach((row, y) => {
        const left = row.indexOf(1);
        const right = row.lastIndexOf(1);
        if (left === right) {
            const isSingle = mat.every((it, index) => {
                if (index === y) return true;
                if (it[left] === 0) return true;
            });
            isSingle && count++;
        }
    });
    return count;
}
// @lc code=end
